package com.ruoyi.column.controller;


import com.ruoyi.column.entity.Column;
import com.ruoyi.column.service.ColumnService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 动态列表对象 前端控制器
 * </p>
 *
 * @author XiaShiLong
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/dynamicList")
@Api("自定义列表")
public class ColumnController {

    private final ColumnService service;

    @Autowired
    public ColumnController(ColumnService service) {
        this.service = service;
    }

    @PreAuthorize("@ss.hasPermi('dynamicList:post:customizeTable')")
    @Log(title = "修改自定义列表", businessType = BusinessType.UPDATE)
    @ApiOperation("修改自定义列表")
    @PostMapping("/customizeTable")
    public AjaxResult customizeTable(@RequestBody List<Column> columnList) {
        return AjaxResult.success(service.customizeTable(columnList));
    }

    @PreAuthorize("@ss.hasPermi('dynamicList:post:restoreDefault')")
    @Log(title = "恢复默认设置", businessType = BusinessType.UPDATE)
    @ApiOperation("恢复默认设置")
    @GetMapping("/restoreDefault/{classPath}")
    public AjaxResult restoreDefault(@PathVariable String classPath) {
        service.restoreDefault(classPath);
        return AjaxResult.success();
    }
}
